#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>

/**
 * NowCoder KY276: Maximal Prime Factor
 */

int main() {
    // Extract numbers from lines
    int n;
    scanf("%d\n", &n);
    std::vector<int> numbers;
    int maxNum = 0;
    while (n-- > 0) {
        std::string line, str;
        std::getline(std::cin, line);
        for (int i = 0; i < line.length(); i++) {
            char c = line[i];
            if (c >= '0' && c <= '9') str.push_back(c);
        }
        int num = str.length() == 0 ? 0 : atoi(str.c_str());
        numbers.push_back(num);
        maxNum = std::max(maxNum, num);
    }

    // Sieve primes
    int maxPrime = int(sqrtf(maxNum));
    std::vector<bool> isPrime(maxPrime + 1, true);
    std::vector<int> primes;
    for (int i = 2; i <= maxPrime; i++) {
        if (!isPrime[i]) continue;
        primes.push_back(i);
        for (int j = i * i; j <= maxPrime; j += i) isPrime[j] = false;
    }

    // Find maximum prime factor
    for (int i = 0; i < numbers.size(); i++) {
        int val = numbers[i];
        if (val == 0) {
            printf("0\n");
            continue;
        }
        int maxPrimeFactor = 0;
        for (int j = 0; j < primes.size(); j++) {
            int p = primes[j];
            while (val % p == 0) {
                val /= p;
                maxPrimeFactor = p;
            }
        }
        maxPrimeFactor = std::max(maxPrimeFactor, val);
        printf("%d\n", maxPrimeFactor);
    }
}